package com.java.yz.day09.ketang;

/*String类的其他功能
    替换功能
        String replace(char old,char new)
        String replace(String old,String new)
    去除字符串两空格
        String trim()
    按字典顺序比较两个字符串
        int compareTo(String str)
        int compareToIgnoreCase(String str)
 */
public class StringDemo5 {
    public static void main(String[] args) {
        String a="shujia000hello666";

        //String replace(char old,char new) //将一个老的字符用新的字符替换
        System.out.println(a.replace('l','s'));
        //shujia000hesso666

        //String replace(String old,String new) //将一个老的字符串用新的字符串替换
        System.out.println(a.replace("shujia","world"));
        //world000hello666

        //String trim()  去除字符串两边空格，中间的不会
        String b="  chifan  ";
        System.out.println(b.trim());

        //int compareTo(String str)  比较两个字符串是否一样
        String S1 = "hello";
        String S2 = "world";
        String S3 = "hel";
        System.out.println(S1.compareTo(S2));  //如果长度相等，就要第一个字符的ASCII码相减
        System.out.println(S1.compareTo(S3));  //长度不等的话就要字符串长度相减5-3

        System.out.println(S1.compareToIgnoreCase(S2));  //以上相同的
        /**S1.compareTo(S2)
         * S1 -- "hello" -- value
         * S2 -- "world"
         * S3 -- "hel"
         * public int compareTo(String anotherString) {
         * int len1 = value.length;
         * int len2 = anotherString.value.length;
         * int lim = Math.min(len1,len2);
         *         byte v1[] = value;
         *         byte v2[] = anotherString.value;
         *         byte coder = coder();
         *         if (coder == anotherString.coder()) {
         *             return coder == LATIN1 ? StringLatin1.compareTo(v1, v2)
         *                                    : StringUTF16.compareTo(v1, v2);
         *         }
         *         return coder == LATIN1 ? StringLatin1.compareToUTF16(v1, v2)
         *                                : StringUTF16.compareToLatin1(v1, v2);
         *      }
         */
    }
}
